package com.javadaemon.rpgengine;

import java.io.IOException;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import com.javadaemon.rpgengine.model.GameState;
import com.javadaemon.rpgengine.util.ResourceManager;
import com.javadaemon.rpgengine.util.XStreamUtil;


/*
 Copyright (c) 2011, Morten Andersen
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
 * The name of the author may not be used to endorse or promote products
 derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL MORTEN ANDERSEN BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * This class is the entry point of the application and the Slick framework.
 * 
 * @author Somnium
 * 
 */
public class GameMain extends BasicGame {

    // Global constants
    public static final int SCREEN_WIDTH = 800;
    public static final int SCREEN_HEIGHT = 600;
    public static final boolean FULLSCREEN = false;
    public static final int TARGET_FPS = 60;
    public static final String GAME_NAME = "Pokemon";

    // The game state of the game.
    private GameState model;

    // Constructor
    public GameMain() {
	super(GAME_NAME);
    }

    @Override
    public void init(GameContainer container) throws SlickException {

	// Initialize ressource manager
	ResourceManager.getRessourceManager();

	// Initialize map
	model = new GameState();
    }

    @Override
    public void update(GameContainer container, int delta)
	    throws SlickException {

	// Update the game state, using the active screen.
	model.getActiveScreen().update(container, delta);
    }

    public void render(GameContainer container, Graphics g)
	    throws SlickException {
	// Render the active screen
	model.getActiveScreen().render(container, g);
    }

    /**
     * Entry point. Initializes the Slick application, using the global constants.
     * 
     * @param args
     */
    public static void main(String[] args) {
	BasicGame game = new GameMain();
	try {
	    AppGameContainer app = new AppGameContainer(game);
	    app.setTargetFrameRate(TARGET_FPS);
	    app.setDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, FULLSCREEN);
	    app.start();
	} catch (SlickException e) {
	    e.printStackTrace();
	}
    }

}
